{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}/Users/fcoell/Dropbox/PATSTAT/DATA/../logs/Table1_app_table12.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}22 Jun 2020, 09:57:57
{txt}
{com}. di "********************* Table 1 and Appendix Table 12  **********************"
{res}********************* Table 1 and Appendix Table 12  **********************
{txt}
{com}. 
. // Define and save raw sample (1. 2. 3)
. use patentsfam4, clear
{txt}
{com}. // 1. firms with non-missing country
. merge m:1 headq using WTOmembers_countries, keep(match) keepusing(headq wto1995)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}      14,150,755{txt}  (_merge==3)
{col 5}{hline 41}

{com}. // 2. firms with non-missing industry
. drop if missing(nace2_1)
{txt}(200,803 observations deleted)

{com}. drop _merge
{txt}
{com}. // 3. firms that file 1+ granted patent in 1992-2000
. gen tmp = (granted > 0) * (y >= 1992 & y <= 2000)
{txt}
{com}. keep if tmp == 1
{txt}(12,403,612 observations deleted)

{com}. contract hrm_l2_id nace2_1 wto1995
{txt}
{com}. drop _freq
{txt}
{com}. merge m:1 hrm_l2_id using hrm_sector, keep(match master)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}       1,053,201{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. count // Number of firms
  {res}1,053,201
{txt}
{com}. save $tmp/raw_sample, replace
{txt}(note: file /tmp/raw_sample.dta not found)
file /tmp/raw_sample.dta saved

{com}. 
. // Define and save initial sample (1. 2. 3. + 4.)
. use $tmp/raw_sample, clear
{txt}
{com}. // 4. Restrict to WTO countries by 1995
. keep if wto1995 == 1
{txt}(289,620 observations deleted)

{com}. count // Number of firms
  {res}763,581
{txt}
{com}. save $tmp/initial_sample, replace
{txt}(note: file /tmp/initial_sample.dta not found)
file /tmp/initial_sample.dta saved

{com}. 
. // Save final sample
. use reg_variables6Granted_WTO, clear
{txt}
{com}. keep if wto1995 == 1
{txt}(38,880 observations deleted)

{com}. gen keep = (P > 0 & y == 1992)
{txt}
{com}. keep if MissTar == 0 & homew < 1 & keep == 1
{txt}(333,276 observations deleted)

{com}. drop keep
{txt}
{com}. contract hrm firm individual other_sector unknown_sector nace2_1
{txt}
{com}. drop _freq
{txt}
{com}. count // Number of firms
  {res}41,058
{txt}
{com}. save $tmp/final_sample, replace 
{txt}(note: file /tmp/final_sample.dta not found)
file /tmp/final_sample.dta saved

{com}. * patentsfam3 includes all firms with pre-sample weights
. * patentsfam4 includes all firms
. 
. // Combine all samples
. use patentsfam4, clear
{txt}
{com}. keep if y > 1991
{txt}(3,437,592 observations deleted)

{com}. merge m:1 hrm_l2_id using $tmp/raw_sample, keep(match master)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       7,690,750
{txt}{col 9}from master{col 30}{res}       7,690,750{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,024,651{txt}  (_merge==3)
{col 5}{hline 41}

{com}. gen raw_sample = _merge == 3
{txt}
{com}. gen initial_sample = (_merge == 3 & wto1995 == 1)
{txt}
{com}. drop _merge
{txt}
{com}. merge m:1 hrm_l2_id using $tmp/final_sample, update replace 
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      10,484,843
{txt}{col 9}from master{col 30}{res}      10,484,843{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}         230,558
{txt}{col 9}not updated{col 30}{res}         106,084{txt}  (_merge==3)
{col 9}missing updated{col 30}{res}          14,974{txt}  (_merge==4)
{col 9}nonmissing conflict{col 30}{res}         109,500{txt}  (_merge==5)
{col 5}{hline 41}

{com}. // (nace codes sometimes differ, keep estimation ones for final sample)
. gen final_sample = _merge >= 3
{txt}
{com}. drop _merge
{txt}
{com}. keep if raw_sample == 1 | initial_sample == 1 | final_sample == 1
{txt}(7,650,553 observations deleted)

{com}. drop p
{txt}
{com}. rename granted p
{res}{txt}
{com}. save $tmp/samples, replace
{txt}(note: file /tmp/samples.dta not found)
file /tmp/samples.dta saved

{com}. 
. 
. // Overall Delta_K for raw, initial and final sample and # firms patenting
. use $tmp/samples, clear
{txt}
{com}. foreach v of varlist *_sample {c -(}
{txt}  2{com}.         di "`v'"
{txt}  3{com}.         use $tmp/samples, clear
{txt}  4{com}.         keep if inrange(y, 1992, 2000)
{txt}  5{com}.         keep if `v' == 1
{txt}  6{com}.         keep if p > 0
{txt}  7{com}.         egen tag = tag(hrm_l2_id)
{txt}  8{com}.         collapse (sum) p firms = tag
{txt}  9{com}.         tabstat p firms
{txt} 10{com}. {c )-}
raw_sample
{txt}(1,321,758 observations deleted)
(5,772 observations deleted)
(190,978 observations deleted)

   stats {...}
{c |}{...}
         p     firms
{hline 9}{c +}{hline 20}
{ralign 8:mean} {...}
{c |}{...}
 {res}  4265689   1053201
{txt}{hline 9}{c BT}{hline 20}
initial_sample
(1,321,758 observations deleted)
(423,856 observations deleted)
(172,996 observations deleted)

   stats {...}
{c |}{...}
         p     firms
{hline 9}{c +}{hline 20}
{ralign 8:mean} {...}
{c |}{...}
 {res}  3644556    763581
{txt}{hline 9}{c BT}{hline 20}
final_sample
(1,321,758 observations deleted)
(1,635,733 observations deleted)
(22,485 observations deleted)

   stats {...}
{c |}{...}
         p     firms
{hline 9}{c +}{hline 20}
{ralign 8:mean} {...}
{c |}{...}
 {res}   663252     30871
{txt}{hline 9}{c BT}{hline 20}

{com}. 
. // Mean Delta_K etc, across firms, for initial and final sample
. /* Note: Delta_K can be 0 in final sample */
. use $tmp/samples, clear
{txt}
{com}. foreach v of varlist *_sample {c -(}
{txt}  2{com}.         di "`v'"
{txt}  3{com}.         use $tmp/samples, clear
{txt}  4{com}.         keep if inrange(y, 1992, 2000)
{txt}  5{com}.         keep if `v' == 1
{txt}  6{com}.         gen px = p
{txt}  7{com}.         gen ptri = triadic
{txt}  8{com}.         gen pcit = p*citations3year
{txt}  9{com}.         collapse (sum) px ptri pcit, by(hrm_l2_id)
{txt} 10{com}.         collapse (mean) px ptri pcit (median) pmed=px ptrimed=ptri pcitmed=pcit ///
>                 (sd) psd=px ptrisd=ptri pcitsd=pcit
{txt} 11{com}.         list
{txt} 12{com}. {c )-}
raw_sample
{txt}(1,321,758 observations deleted)
(5,772 observations deleted)

     {c TLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c TRC}
     {c |} {res}      px       ptri       pcit   pmed   ptrimed   pcitmed        psd     ptrisd    pcitsd {txt}{c |}
     {c LT}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c RT}
  1. {c |} {res}4.050214   .1535016   10.56388      1         0         0   122.6154   12.74086   516.152 {txt}{c |}
     {c BLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 9}{c BRC}
initial_sample
(1,321,758 observations deleted)
(423,856 observations deleted)

     {c TLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c TRC}
     {c |} {res}      px       ptri       pcit   pmed   ptrimed   pcitmed        psd     ptrisd     pcitsd {txt}{c |}
     {c LT}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c RT}
  1. {c |} {res}4.772979   .2114877   14.29904      1         0         0   143.5747   14.96284   605.2876 {txt}{c |}
     {c BLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c BRC}
final_sample
(1,321,758 observations deleted)
(1,635,733 observations deleted)

     {c TLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c TRC}
     {c |} {res}      px       ptri       pcit   pmed   ptrimed   pcitmed        psd     ptrisd     pcitsd {txt}{c |}
     {c LT}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c RT}
  1. {c |} {res}19.60196   .8768471   54.30645      2         0         1   329.6262   19.76391   971.7852 {txt}{c |}
     {c BLC}{hline 10}{c -}{hline 10}{c -}{hline 10}{c -}{hline 6}{c -}{hline 9}{c -}{hline 9}{c -}{hline 10}{c -}{hline 10}{c -}{hline 10}{c BRC}

{com}. 
. // Number of firms in raw, initial and final sample
. use $tmp/samples, clear
{txt}
{com}. foreach v of varlist *_sample {c -(}
{txt}  2{com}.         di "`v'"
{txt}  3{com}.         use $tmp/samples, clear
{txt}  4{com}.         keep if `v' == 1
{txt}  5{com}.         contract hrm_l2_id
{txt}  6{com}.         collapse (count) firms = hrm_l2_id
{txt}  7{com}.         list
{txt}  8{com}. {c )-}
raw_sample
{txt}(40,197 observations deleted)

     {c TLC}{hline 9}{c TRC}
     {c |} {res}  firms {txt}{c |}
     {c LT}{hline 9}{c RT}
  1. {c |} {res}1053201 {txt}{c |}
     {c BLC}{hline 9}{c BRC}
initial_sample
(824,696 observations deleted)

     {c TLC}{hline 8}{c TRC}
     {c |} {res} firms {txt}{c |}
     {c LT}{hline 8}{c RT}
  1. {c |} {res}763581 {txt}{c |}
     {c BLC}{hline 8}{c BRC}
final_sample
(2,834,290 observations deleted)

     {c TLC}{hline 7}{c TRC}
     {c |} {res}firms {txt}{c |}
     {c LT}{hline 7}{c RT}
  1. {c |} {res}41058 {txt}{c |}
     {c BLC}{hline 7}{c BRC}

{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}/Users/fcoell/Dropbox/PATSTAT/DATA/../logs/Table1_app_table12.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}22 Jun 2020, 09:59:22
{txt}{.-}
{smcl}
{txt}{sf}{ul off}